<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>Document</title>
		<!-- 引入样式 -->
		<link rel="stylesheet" href="../../plugins/element-ui/index.css" />
		<link rel="stylesheet" href="../../styles/common.css" />
		<link rel="stylesheet" href="../../styles/page.css" />
		<style>
			#member-app .notAdmin::after {
				border: 0 !important;
			}
		</style>
	</head>
	<body>
		<div class="dashboard-container" id="admin-app">
			<div class="container">
				<div class="tableBar">
					<el-input v-model="input" placeholder="请输入管理员姓名" style="width: 250px" clearable
						@keyup.enter.native="handleQuery">
						<i slot="prefix" class="el-input__icon el-icon-search" style="cursor: pointer" @click="handleQuery"></i>
					</el-input>
					<el-button type="primary" icon="el-icon-search" @click="init" style="margin-left: 10px">搜索</el-button>
					<el-button type="primary" @click="addMemberHandle('add')">+ 添加管理员</el-button>
				</div>
				<!--员工分页展示table-->
				<el-table :data="tableData" stripe class="tableBox">
					<el-table-column prop="nickname" label="管理员昵称" align="center"></el-table-column>
					<el-table-column prop="username" label="账号" align="center"></el-table-column>
					<el-table-column prop="name" label="真实姓名" align="center"></el-table-column>
					<el-table-column prop="type" label="管理员类型" align="center"></el-table-column>
					<el-table-column prop="image" label="头像" align="center">
						<template slot-scope="{ row }">
							<el-image style="width: auto; height: 40px; border:none;cursor: pointer;" :src="getImage(row.image)"
								:preview-src-list="[ getImage(row.image) ]">
								<div slot="error" class="image-slot">
									<img src="../../images/noImg.png" style="width: auto; height: 40px; border:none;">
								</div>
							</el-image>
						</template>
					</el-table-column>
					<el-table-column label="账号状态">
						<template slot-scope="scope">
							{{ String(scope.row.status) === '0' ? '已禁用' : '正常' }}
						</template>
					</el-table-column>
					<el-table-column label="操作" width="160" align="center">
						<template slot-scope="scope" v-if="loginAdmin.type=='超级管理员'">
							<el-button type="text" size="small" class="blueBug" @click="addMemberHandle(scope.row.adminId)">
								编辑
							</el-button>
							<el-button type="text" size="small" class="delBut non" @click="statusHandle(scope.row)">
								{{ scope.row.status == '1' ? '禁用' : '启用' }}
							</el-button>
						</template>
					</el-table-column>
				</el-table>
				<!--page-sizes 条目数 -->
				<el-pagination class="pageList" :page-sizes="[10,20,30,40,50]" :page-size="pageSize"
					layout="total, sizes, prev, pager, next, jumper" :total="counts" :current-page.sync="page"
					@size-change="handleSizeChange" @current-change="handleCurrentChange"></el-pagination>
			</div>
		</div>
		<!-- 开发环境版本，包含了有帮助的命令行警告 -->
		<script src="../../plugins/vue/vue.js"></script>
		<!-- 引入组件库 -->
		<script src="../../plugins/element-ui/index.js"></script>
		<!-- 引入axios -->
		<script src="../../plugins/axios/axios.min.js"></script>
		<script src="../../js/request.js"></script>
		<script src="../../api/admin.js"></script>
		<script>
			new Vue({
				el: '#admin-app',
				data() {
					return {
						loginAdmin:'',
						input: '',
						counts: 0,
						page: 1,
						pageSize: 10,
						tableData: [{
							'adminId': '',
							'username': '',
							'password': '',
							'name': '',
							'nickname': '',
							'age': '',
							'birthday': '',
							'type': '',
							'email': '',
							'phone': '',
							'image': '',
							'idNumber': '',
						}],
						id: '',
						status: '',
					}
				},
				/*vue初始化挂载函数*/
				created() {
					// 获取用户的登录用户信息用来做权限标签
					this.loginAdmin = JSON.parse(window.localStorage.getItem('userInfo'));
					this.init();
					// alert(1439057691107037185);//js失去精度测试
					if (localStorage.getItem('userInfo') != null) {
						//获取当前登录员工的账号，并赋值给模型数据
						this.user = JSON.parse(localStorage.getItem('userInfo')).username;
					}
				},
				methods: {
					async init() {
						const params = {
							page: this.page,
							pageSize: this.pageSize,
							name: this.input ? this.input : undefined
						};
						await getAdminList(params).then(res => { //res === res.data
							if (String(res.code) === '1') {
								this.tableData = res.data.records || [];
								this.tableData.map(item => {
									image: $minioUrl + "" + item.image
								})
								this.counts = res.data.total
								console.log("*******")
							}
						}).catch(err => {
							this.$message.error('请求出错了：' + err)
						})
					},
					handleQuery() {
						this.page = 1;
						this.init();
					},
					getImage(image) {
						return $minioUrl+image
					},
					// 添加&修改跳转
					addMemberHandle(st) {
						if (st === 'add') {
							window.parent.menuHandle({
								id: '11',
								url: 'page/admin/add.html',
								name: '添加管理员'
							}, true)
						} else {
							window.parent.menuHandle({
								id: '11',
								url: 'page/admin/update.html?id=' + st, //跳转到add.html页面并携带一个id参数
								name: '修改管理员'
							}, true)
						}
					},
					//状态修改
					statusHandle(row) {
						this.adminId = row.adminId;
						this.status = row.status;
						this.$confirm('确认调整该账号的状态?', '提示', {
							'confirmButtonText': '确定',
							'cancelButtonText': '取消',
							'type': 'warning'
						}).then(() => { //点击确定执行
							// 调用请求方法   0--false----true   1---true---0
							//this.status=="0"||this.status==0 ? "1" : "0"    long -> string  this.status  string  true
							enableOrDisableAdmin({
								'adminId': this.adminId,
								'status': this.status
							}).then(res => { //请求结果处理
								if (String(res.code) === '1') {
									this.$message.success('账号状态更改成功！');
									this.handleQuery()
								} else {
									this.$message.error(res.msg)
								}
							}).catch(err => {
								this.$message.error('请求出错了：' + err)
							})
						})
					},
					handleSizeChange(val) {
						this.pageSize = val;
						this.init()
					},
					handleCurrentChange(val) {
						this.page = val;
						this.init()
					}
				}
			})
		</script>
	</body>
</html>